
//
//  VisitorLoginView.swift
//  CXWeibo
//
//  Created by mac on 15/6/6.
//  Copyright (c) 2015年 itcast. All rights reserved.
//

import UIKit

protocol VisitorLoginViewDelegate: NSObjectProtocol{

    /// 选中注册按钮
    func didSeledRegisterButton()
    
    /// 选中登录按钮
    func didSeledLoginButton()
    
}

class VisitorLoginView: UIView {

   
    @IBOutlet weak var smallIconView: UIImageView!
    
    @IBOutlet weak var houseIconView: UIImageView!
    
    @IBOutlet weak var messageLabel: UILabel!
    
    
    /// 定义代理
    weak var delegate:VisitorLoginViewDelegate?
    
    /// 点击登录按钮
    @IBAction func login(sender: UIButton) {
        
        delegate?.didSeledLoginButton()
        
        println(__FUNCTION__)
    }
    
    
    /// 点击注册按钮
    @IBAction func register() {
        
        delegate?.didSeledRegisterButton()
        
        println(__FUNCTION__)
    }
    
    func setupInfo(iconName: String, message:String, isHome: Bool = false){
        
        houseIconView.hidden = !isHome
        if isHome{
        
            houseIconView.image = UIImage(named: iconName)
            smallIconView.image = UIImage(named: "visitordiscover_feed_image_smallicon")
            
            startAnimation()
            
        }else{
        
            smallIconView.image = UIImage(named: iconName)
        }
        
        messageLabel.text = message
        
        isHome ? startAnimation() : stopAnimation()
    
    }
    
    /// 开始动画
    private func startAnimation(){
        
        let anim = CABasicAnimation(keyPath: "transform.rotation")
        anim.repeatCount = MAXFLOAT
        anim.toValue = 2 * M_PI
        anim.duration = 20.0
        
        // 在像图层中，添加动画时，如果指定了key,图层会对动画强引用
        smallIconView.layer.addAnimation(anim, forKey: "rotation")
        
    }
    
    /// 停止动画
    private func stopAnimation(){
    
        smallIconView.layer.removeAllAnimations()
    }
    
    
    
    
    
}
